<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Hexo,Github," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="此文使用的 hexo版本  3.1.1已经换过好几个博客平台，国内的用过博客园、51CTO、csdn，总体的感觉是，界面都不够简介，插入代码困难，致命的是侧边栏有广告。国外的用过codrspace，Medium, 界面都很简洁，但是前者很久没更新过了，后者偶尔被墙。这些不利因素都影响到写博客的积极性。于是有了自己搭建博客的想法。网上了解到可以在Github上写博客，很是高兴。在开发者眼中，Gith">
<meta property="og:type" content="article">
<meta property="og:title" content="Hexo+Github搭建自己的博客">
<meta property="og:url" content="http://yoursite.com/2016/02/26/Other/Hexo-Github搭建自己的博客/index.html">
<meta property="og:site_name" content="ZhouJiatao's Blog">
<meta property="og:description" content="此文使用的 hexo版本  3.1.1已经换过好几个博客平台，国内的用过博客园、51CTO、csdn，总体的感觉是，界面都不够简介，插入代码困难，致命的是侧边栏有广告。国外的用过codrspace，Medium, 界面都很简洁，但是前者很久没更新过了，后者偶尔被墙。这些不利因素都影响到写博客的积极性。于是有了自己搭建博客的想法。网上了解到可以在Github上写博客，很是高兴。在开发者眼中，Gith">
<meta property="og:image" content="http://7xr5jb.com1.z0.glb.clouddn.com/expression%23haha.png">
<meta property="og:image" content="http://7xr5jb.com1.z0.glb.clouddn.com/expression%23pipe.jpg">
<meta property="og:image" content="http://7xr5jb.com1.z0.glb.clouddn.com/Hexo%2BGithub%23CopyURL.png">
<meta property="og:updated_time" content="2017-01-13T04:46:12.189Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hexo+Github搭建自己的博客">
<meta name="twitter:description" content="此文使用的 hexo版本  3.1.1已经换过好几个博客平台，国内的用过博客园、51CTO、csdn，总体的感觉是，界面都不够简介，插入代码困难，致命的是侧边栏有广告。国外的用过codrspace，Medium, 界面都很简洁，但是前者很久没更新过了，后者偶尔被墙。这些不利因素都影响到写博客的积极性。于是有了自己搭建博客的想法。网上了解到可以在Github上写博客，很是高兴。在开发者眼中，Gith">
<meta name="twitter:image" content="http://7xr5jb.com1.z0.glb.clouddn.com/expression%23haha.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2016/02/26/Other/Hexo-Github搭建自己的博客/"/>





  <title> Hexo+Github搭建自己的博客 | ZhouJiatao's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  


<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  ga('create', 'UA-91431386-1', 'auto');
  ga('send', 'pageview');
</script>









  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">ZhouJiatao's Blog</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
    
      <p class="site-subtitle"></p>
    
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
  <link itemprop="mainEntityOfPage" href="http://yoursite.com/2016/02/26/Other/Hexo-Github搭建自己的博客/">

  <span style="display:none" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <meta itemprop="name" content="ZhouJiatao">
    <meta itemprop="description" content="">
    <meta itemprop="image" content="http://7xr5jb.com1.z0.glb.clouddn.com/avatar%23privateinvestocat.jpg">
  </span>

  <span style="display:none" itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
    <meta itemprop="name" content="ZhouJiatao's Blog">
    <span style="display:none" itemprop="logo" itemscope itemtype="http://schema.org/ImageObject">
      <img style="display:none;" itemprop="url image" alt="ZhouJiatao's Blog" src="">
    </span>
  </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Hexo+Github搭建自己的博客
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2016-02-26T10:02:03+00:00">
                2016-02-26
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Tools-Resources/" itemprop="url" rel="index">
                    <span itemprop="name">Tools/Resources</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2016/02/26/Other/Hexo-Github搭建自己的博客/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count ds-thread-count" data-thread-key="2016/02/26/Other/Hexo-Github搭建自己的博客/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          

          
          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong><em>此文使用的 hexo版本  3.1.1</em></strong><br>已经换过好几个博客平台，国内的用过博客园、51CTO、csdn，总体的感觉是，界面都不够简介，插入代码困难，致命的是侧边栏有广告。国外的用过codrspace，Medium, 界面都很简洁，但是前者很久没更新过了，后者偶尔被墙。这些不利因素都影响到写博客的积极性。<br>于是有了自己搭建博客的想法。<br>网上了解到可以在Github上写博客，很是高兴。在开发者眼中，Github就是高端的代名词嘛。<br>一开始使用Hexo，我是拒绝的。</p>
<p><img src="http://7xr5jb.com1.z0.glb.clouddn.com/expression%23haha.png" alt="happy"></p>
<a id="more"></a>
<p>因为在Google用关键字搜索 “blog github”,满是Jekyll的身影，却不见Hexo。感觉Jekyll资料肯定会更加齐全。<br>了解到Jekyll的配置有多繁琐后，我欣然接受Hexo。</p>
<p><img src="http://7xr5jb.com1.z0.glb.clouddn.com/expression%23pipe.jpg" alt="pipe"></p>
<p>事实上Hexo的资料也是很齐全的，并且在Github上有许多主题可以下载。<br>而且在生成静态页面的效率上，Hexo也是远高于Jekyll的。</p>
<h1 id="安装必要的软件"><a href="#安装必要的软件" class="headerlink" title="安装必要的软件"></a>安装必要的软件</h1><h2 id="Node-js"><a href="#Node-js" class="headerlink" title="Node.js"></a>Node.js</h2><p>作用：用于生成静态页面。<br>进入<a href="https://nodejs.org/" target="_blank" rel="external">Node.js官网</a>下载安装包即可进行安装。</p>
<h2 id="git"><a href="#git" class="headerlink" title="git"></a>git</h2><p>作用：用于提交本地内容，比如主题、hexo生成的静态文件。<br>Xcode自带git，如果你安装过Xcode，可以跳过这一步。<br>如果没有，请自觉进入<a href="http://git-scm.com/download/" target="_blank" rel="external">git官网</a>下载安装包。</p>
<h2 id="Hexo"><a href="#Hexo" class="headerlink" title="Hexo"></a>Hexo</h2><p>在终端执行以下命令进行安装</p>
<pre><code>$ sudo npm install -g hexo
</code></pre><h1 id="初始化Hexo"><a href="#初始化Hexo" class="headerlink" title="初始化Hexo"></a>初始化Hexo</h1><p>安装完成后，进入你想要存放 <em>本地文件(包含 主题、博客文件、网站的静态文件)</em> 的目录，并执行</p>
<pre><code>$ hexo init
$ npm install
</code></pre><p>初始化完成后，目录结构就像这样：</p>
<pre><code>. 
├── _config.yml 
├── package.json 
├── scaffolds 
├── source 
| ├── _drafts 
| └── _posts 
└── themes
</code></pre><h1 id="启动本地服务"><a href="#启动本地服务" class="headerlink" title="启动本地服务"></a>启动本地服务</h1><p>用于预览本地文章</p>
<pre><code>$ hexo server
</code></pre><p>浏览器访问 <a href="http://localhost:4000" target="_blank" rel="external">http://localhost:4000</a><br>如果能打开，说明本地的环境配置成功了。</p>
<h1 id="配置Github"><a href="#配置Github" class="headerlink" title="配置Github"></a>配置Github</h1><p>你的需要一个Github帐号，没有就到<a href="https://github.com" target="_blank" rel="external">这里</a>免费注册一个。<br><strong>登录Github，建立仓库(Repository)，命名格式为<code>user_name.github.io</code></strong><br>比如，你的用户名为RealMeZJT,仓库名称应为”RealMeZJT.github.io”</p>
<h1 id="关联Hexo-和-Github"><a href="#关联Hexo-和-Github" class="headerlink" title="关联Hexo 和 Github"></a>关联Hexo 和 Github</h1><h2 id="复制repository-url"><a href="#复制repository-url" class="headerlink" title="复制repository url"></a>复制repository url</h2><p>登录Github，点击进入你的仓库，复制你刚才创建的仓库的url<br><img src="http://7xr5jb.com1.z0.glb.clouddn.com/Hexo%2BGithub%23CopyURL.png" alt="repositoryUrl"></p>
<h2 id="将repository-url写入配置文件"><a href="#将repository-url写入配置文件" class="headerlink" title="将repository url写入配置文件"></a>将repository url写入配置文件</h2><p>用文本编辑器打开 _config.yml 文件，滚动到最低端，编辑最后一部份:</p>
<pre><code>deploy: 
  type: git 
  repo: &lt;repository url&gt;
</code></pre><p><em>注意：分号后有空格，不能漏写。</em><br>以下是我自己的配置</p>
<pre><code>deploy:
  type: git
  repo: https://github.com/RealMeZJT/RealMeZJT.github.io.git
</code></pre><p>配置完成后执行:</p>
<pre><code>$ hexo deploy
</code></pre><p><em>(首次提交会提示你输入Github密码)</em><br>现在你可以通过浏览器访问到你的博客，地址是 <code>http://user_name.github.io</code><br>比如我的用户名是RealMeZJT，那么我的博客地址是 <a href="http://realmezjt.github.io" target="_blank" rel="external">http://realmezjt.github.io</a></p>
<h1 id="附-常用Hexo命令"><a href="#附-常用Hexo命令" class="headerlink" title="附 常用Hexo命令"></a>附 常用Hexo命令</h1><h2 id="新建文章"><a href="#新建文章" class="headerlink" title="新建文章"></a>新建文章</h2><pre><code>$ hexo new &quot;postName&quot;
</code></pre><p>新建后在 <code>source/_posts</code> 目录下可以看到<code>.md</code>后缀文件，文件名与文章名相同。打开文件，可用<a href="http://realmezjt.github.io/2016/02/23/初识Markdown/" target="_blank" rel="external">Markdown</a>标记语言编辑你的新文章。</p>
<h2 id="提交到Github"><a href="#提交到Github" class="headerlink" title="提交到Github"></a>提交到Github</h2><p>每次都可以依次运行这3个命令</p>
<pre><code>$ hexo clean
$ hexo generate
$ hexo deploy
</code></pre><p>更多的知识，请参阅官方文档 <a href="https://hexo.io/zh-cn/" target="_blank" rel="external">https://hexo.io/zh-cn/</a></p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Hexo/" rel="tag"># Hexo</a>
          
            <a href="/tags/Github/" rel="tag"># Github</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/02/25/iOS/在代码中修改constraint的值/" rel="next" title="在代码中修改constraint的值">
                <i class="fa fa-chevron-left"></i> 在代码中修改constraint的值
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2016/02/26/iOS/如何让UIViewController透明/" rel="prev" title="如何让UIViewController透明">
                如何让UIViewController透明 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div class="ds-thread" data-thread-key="2016/02/26/Other/Hexo-Github搭建自己的博客/"
           data-title="Hexo+Github搭建自己的博客" data-url="http://yoursite.com/2016/02/26/Other/Hexo-Github搭建自己的博客/">
      </div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="http://7xr5jb.com1.z0.glb.clouddn.com/avatar%23privateinvestocat.jpg"
               alt="ZhouJiatao" />
          <p class="site-author-name" itemprop="name">ZhouJiatao</p>
          <p class="site-description motion-element" itemprop="description">Write simple code</p>
        </div>
        <nav class="site-state motion-element">
        
          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">29</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">5</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">18</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/RealMeZJT" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#安装必要的软件"><span class="nav-number">1.</span> <span class="nav-text">安装必要的软件</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Node-js"><span class="nav-number">1.1.</span> <span class="nav-text">Node.js</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#git"><span class="nav-number">1.2.</span> <span class="nav-text">git</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Hexo"><span class="nav-number">1.3.</span> <span class="nav-text">Hexo</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#初始化Hexo"><span class="nav-number">2.</span> <span class="nav-text">初始化Hexo</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#启动本地服务"><span class="nav-number">3.</span> <span class="nav-text">启动本地服务</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#配置Github"><span class="nav-number">4.</span> <span class="nav-text">配置Github</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#关联Hexo-和-Github"><span class="nav-number">5.</span> <span class="nav-text">关联Hexo 和 Github</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#复制repository-url"><span class="nav-number">5.1.</span> <span class="nav-text">复制repository url</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#将repository-url写入配置文件"><span class="nav-number">5.2.</span> <span class="nav-text">将repository url写入配置文件</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#附-常用Hexo命令"><span class="nav-number">6.</span> <span class="nav-text">附 常用Hexo命令</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#新建文章"><span class="nav-number">6.1.</span> <span class="nav-text">新建文章</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#提交到Github"><span class="nav-number">6.2.</span> <span class="nav-text">提交到Github</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">ZhouJiatao</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  

  
    
  

  <script type="text/javascript">
    var duoshuoQuery = {short_name:"realmezjt"};
    (function() {
      var ds = document.createElement('script');
      ds.type = 'text/javascript';ds.async = true;
      ds.id = 'duoshuo-script';
      ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
      ds.charset = 'UTF-8';
      (document.getElementsByTagName('head')[0]
      || document.getElementsByTagName('body')[0]).appendChild(ds);
    })();
  </script>

  
    
    
    <script src="/lib/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>
    <script src="/js/src/hook-duoshuo.js"></script>
  












  
  

  

  

  

  


</body>
</html>
